package com.jing.mvp_demo.Presenter;

import com.jing.mvp_demo.Model.User;
import com.jing.mvp_demo.View.LoginView;

public class LoginPresenter {
    private LoginView loginView;

    public LoginPresenter(LoginView loginView) {
        this.loginView = loginView;
    }

    public void validateCredentials(String username, String password) {

        User user = new User(username, password);
        if (username.isEmpty()) {
            loginView.setUsernameError();
            return;
        }
        if (password.isEmpty()) {
            loginView.setPasswordError();
            return;
        }

        if (user.isValid()) {
            loginView.navigateToHome();
        } else {
            loginView.setPasswordError();
        }
    }
}